package com.lyc.mapper;

import com.lyc.pojo.InternshipJobs;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface InternshipJobsMapper {
    // 插入实习/兼职信息
    @Insert("INSERT INTO internship_jobs (" +
            "post_id, job_type, job_title, company_name, industry, company_description, " +
            "job_description, job_responsibilities, job_requirements, benefits, " +
            "work_location, work_address_detail, work_mode, work_duration, work_schedule, weekly_days, " +
            "salary_type, min_salary, max_salary, salary_remark, " +
            "education_requirement, recruitment_count, deadline, start_date, graduation_year, " +
            "contact_person, contact_department, contact_email, contact_phone, application_method, " +
            "job_tags, is_verified, verification_info, urgency_level, created_at, updated_at) " +
            "VALUES (" +
            "#{postId}, #{jobType}, #{jobTitle}, #{companyName}, #{industry}, #{companyDescription}, " +
            "#{jobDescription}, #{jobResponsibilities}, #{jobRequirements}, #{benefits}, " +
            "#{workLocation}, #{workAddressDetail}, #{workMode}, #{workDuration}, #{workSchedule}, #{weeklyDays}, " +
            "#{salaryType}, #{minSalary}, #{maxSalary}, #{salaryRemark}, " +
            "#{educationRequirement}, #{recruitmentCount}, #{deadline}, #{startDate}, #{graduationYear}, " +
            "#{contactPerson}, #{contactDepartment}, #{contactEmail}, #{contactPhone}, #{applicationMethod}, " +
            "#{jobTags}, #{isVerified}, #{verificationInfo}, #{urgencyLevel}, now(), now())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertInternshipJob(InternshipJobs internshipJobs);

    // 更新实习/兼职信息浏览次数
    @Update("UPDATE internship_jobs SET view_count = view_count + 1 WHERE id = #{id}")
    void incrementViewCount(Integer id);
    
    // 根据postId删除实习/兼职信息
    @Delete("DELETE FROM internship_jobs WHERE post_id = #{postId}")
    void deleteByPostId(Integer postId);
    
    // 获取所有实习/兼职信息列表
    @Select("SELECT * FROM internship_jobs ORDER BY created_at DESC")
    List<InternshipJobs> getAllInternshipJobs();
    
    // 根据ID获取实习/兼职信息详情
    @Select("SELECT * FROM internship_jobs WHERE id = #{id}")
    InternshipJobs getInternshipJobById(Integer id);
    
    // 根据postId获取实习/兼职信息详情
    @Select("SELECT * FROM internship_jobs WHERE post_id = #{postId}")
    InternshipJobs getInternshipJobByPostId(Integer postId);
    
    // 根据实习/兼职信息ID获取对应的postId
    @Select("SELECT post_id FROM internship_jobs WHERE id = #{id}")
    Integer getPostIdById(Integer id);

    // 根据行业获取实习/兼职信息列表
    @Select("SELECT * FROM internship_jobs WHERE industry = #{industry}")
    List<InternshipJobs> getIndustryList(String industry);
}